/*
 * Filename AgeSegment.java 2021年09月29日
 * Copyright © Ehome Co.Ltd. All Rgiths Reserved.
 * @author gaojun
 */
package com.ehome.poct.core.api.dto.common;

import com.ehome.poct.core.api.common.Age;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 年龄分段
 *
 * @author muqiu1
 * @since 2022/03/04 17:12
 **/
@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum AgeSegment {
    /**
     * 成人
     */
    ADULT("成人", 1),

    /**
     * 儿童
     */
    CHILD("儿童", 2);

    /**
     * 成人年份标准
     */
    public static final int ADULT_YEAR_STANDARD_BLD = 14;
    public static final int ADULT_YEAR_STANDARD_JBY = 3;

    private final String desc;
    private final int value;

    public static AgeSegment getByAge(Age age, int standard) {
        if (age.getYear() == null && age.getMonth() == null) {
            return ADULT;
        }
        if (age.getYear() == null || age.getYear() <= standard) {
            return CHILD;
        }
        return ADULT;
    }
}
